package dk.twu.analyzer.console;

import dk.twu.analyzer.console.model.ICommandElement;

import java.util.Stack;

/**
 * Created by TW on 12/22/2014.
 */
public class CommandStack {
    private final Stack<ICommandElement> commandElementStack;

    public CommandStack() {
        this.commandElementStack = new Stack<>();
    }

    public void push(ICommandElement commandElement) {
        if (commandElement != null) {
            this.commandElementStack.push(commandElement);
        }
    }

    public ICommandElement pop() {
        return this.commandElementStack.pop();
    }

    public ICommandElement getTopElement() {
        return this.commandElementStack.firstElement();
    }

    public int size() {
        return this.commandElementStack.size();
    }

    public String getDescription() {
        StringBuffer result = new StringBuffer();
        this.commandElementStack.stream().forEach(element -> result.append(element.getShortDescription()).append("<-"));
        result.append("END");
        return result.toString();
    }

    public void clear() {
        this.commandElementStack.clear();
        return;
    }
}
